public class 求pi的近似值 {
    public static void main(String[] args) {
        double pi = 1;
        int flag = -1;
        for (int i = 3; i < 1000000000; i += 2) {
            pi = pi + flag * (1.0 / i);
            flag = -flag;
        }
        System.out.println("pi的近似值为"+4 * pi);
    }
}


